package com.dream.keigezhushou.Activity.acty.listen.golden;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.dream.keigezhushou.Activity.acty.listen.local.SearchMusicActivity;
import com.dream.keigezhushou.Activity.acty.listen.myview.ItemRemoveRecylerView30sImake;
import com.dream.keigezhushou.Activity.activity.BaseActivity;
import com.dream.keigezhushou.Activity.adapter.ThirdAdapter;
import com.dream.keigezhushou.Activity.pop.MoreWindow;
import com.dream.keigezhushou.Activity.pop.MoreWindowToMusicMessage;
import com.dream.keigezhushou.Activity.view.OnItemClickListener;
import com.dream.keigezhushou.Activity.wigdt.DividerItemDeoration;
import com.dream.keigezhushou.R;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ChooseLocalMusicActivity extends AppCompatActivity implements View.OnClickListener {


    @BindView(R.id.ib_return)
    ImageView ibReturn;
    @BindView(R.id.ib_search_localmusic)
    Button ibSearchLocalmusic;
    @BindView(R.id.localmusic)
    TextView localmusic;
    @BindView(R.id.rl_ltitle)
    RelativeLayout rlLtitle;
    @BindView(R.id.rcv_Local)
    ItemRemoveRecylerView30sImake rcvLocal;
    @BindView(R.id.activity_choose_local_music)
    LinearLayout activityChooseLocalMusic;
    private ArrayList<String> mms;
    private ThirdAdapter thirdAdapter;
    private Intent intent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_choose_local_music);
        ButterKnife.bind(this);

        initMMs();
        setListeners();


        //获取歌曲数据


    }

    private void initMMs() {
        mms = new ArrayList<String>();
        for (int i = 0; i < 20; i++) {
            mms.add("" + (char) i);

        }


        thirdAdapter = new ThirdAdapter(this, mms);

        rcvLocal.setLayoutManager(new LinearLayoutManager(this));
        rcvLocal.setAdapter(thirdAdapter);

        rcvLocal.addItemDecoration(new DividerItemDeoration(this, DividerItemDeoration.VERTICAL_LIST));
        thirdAdapter.addHeaderView(View.inflate(this, R.layout.golde30s_collecte_headerview, null));
        thirdAdapter.addFootView(View.inflate(this, R.layout.golde30s_collecte_footview, null));

        thirdAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {

            }

            @Override
            public void onDeleteClick(int mPosition) {

            }

            @Override
            public void onItemMoreClick(int position) {

                final MoreWindow moreWindow = new MoreWindow(View.inflate(ChooseLocalMusicActivity.this, R.layout.golde30s_pupwindow, null), ChooseLocalMusicActivity.this, RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT);
                moreWindow.showPopAtLocation(rcvLocal, Gravity.BOTTOM);
                moreWindow.setItemListener(new MoreWindow.ItemClickListener() {
                    @Override
                    public void onClick() {
//                        Toast.makeText(HotRecommendActivity.this, "好样", Toast.LENGTH_SHORT).show();

                    }

                    @Override
                    public void onSingDetail() {


                        WindowManager wm = (WindowManager) ChooseLocalMusicActivity.this
                                .getSystemService(Context.WINDOW_SERVICE);

                        int width = wm.getDefaultDisplay().getWidth();
                        int height = wm.getDefaultDisplay().getHeight();


                        MoreWindowToMusicMessage moreWindowToMusicMessage = new MoreWindowToMusicMessage(View.inflate(ChooseLocalMusicActivity.this, R.layout.pop_musicmessage, null), ChooseLocalMusicActivity.this, width, ViewGroup.LayoutParams.WRAP_CONTENT);
//                       moreWindow.setBackColorState(0);
                        moreWindowToMusicMessage.showPopAtLocation(rcvLocal, Gravity.BOTTOM);
                        moreWindow.backGroundAlpha(0.4f);


                    }
                });


            }
        });

        rcvLocal.setOnItemClickListener(new OnItemClickListener() {
            public Intent intent;

            @Override
            public void onItemClick(View view, int position) {
                Toast.makeText(ChooseLocalMusicActivity.this, "** " + mms.get(position - 1) + " **", Toast.LENGTH_SHORT).show();
                intent = new Intent(ChooseLocalMusicActivity.this, Golde30sMuscWordsActivity.class);
                startActivity(intent);


            }

            @Override
            public void onDeleteClick(int mPosition) {
                if (mPosition > 0) {
                    thirdAdapter.removeItem(mPosition - 1);
                }
            }

            @Override
            public void onItemMoreClick(int position) {

            }
        });


    }


//    private void setAdapter() {
////   madapter=new MusicAdapter(madapter);
////        listViewLocalMusic.setAdapter(madapter);
//////
////       listViewLocalMusic.setAdapter(madapter);
////        listViewLocalMusic.setEmptyView();
//
//    }


    private void setListeners() {
        ibReturn.setOnClickListener(this);
        ibSearchLocalmusic.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ib_return:
                finish();
                break;
            case R.id.ib_search_localmusic:
                Toast.makeText(this, "跳转到文件夹扫描本地音乐", Toast.LENGTH_SHORT).show();
                intent = new Intent(ChooseLocalMusicActivity.this, SearchMusicActivity.class);
                startActivity(intent);

                break;


        }
    }


}


